package CaseTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import junit.framework.TestCase;

public class EmptyUtilsTest extends TestCase{

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	/*
	 * 测试Collection是否为空
	 */
	@Test
    public static void testCollectionIsEmpty() {
        List<Integer> list = Arrays.asList(1, 2, 3);//存储list
        boolean listWithPositiveSize = EmptyUtils.isEmpty(list);//判断输入的是否为空
        assertFalse(listWithPositiveSize);//断言条件的真假

        List<Integer> emptyList = new ArrayList<Integer>();
        boolean listWithZeroSize = EmptyUtils.isEmpty(emptyList);
        assertTrue(listWithZeroSize);

        List<Integer> nullList = null;
        boolean nullEmpty = EmptyUtils.isEmpty(nullList);
        assertTrue(nullEmpty);

        Set<Integer> set = new HashSet<Integer>();
        set.add(100);
        boolean setWithPositiveSize = EmptyUtils.isEmpty(set);
        assertFalse(setWithPositiveSize);

        Set<Integer> nullSet = null;
        assertTrue(EmptyUtils.isEmpty(nullSet));

        Set<Integer> emptySet = new HashSet<Integer>();
        assertTrue(EmptyUtils.isEmpty(emptySet));
    }

	
	/*
	 * 判断Map是否为空
	 */
    @Test
    public static void testMapIsEmpty() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("mapTest", "mapTestValue");
        assertFalse(EmptyUtils.isEmpty(map));

        Map<String, Object> nullEmpty = null;
        assertTrue(EmptyUtils.isEmpty(nullEmpty));

Map<String, Object> emptyMap = new HashMap<String, Object>();
        assertTrue(EmptyUtils.isEmpty(emptyMap));
    }

    /*
     * 判断数组是否为空
     */
    @Test
    public static void testObjectArrayIsEmpty() {
        Integer[] array = { 1, 2, 3 };
        assertFalse(EmptyUtils.isEmpty(array));

        Integer[] nullArray = null;
        assertTrue(EmptyUtils.isEmpty(nullArray));

        Integer[] emptyArray = {};
        assertTrue(EmptyUtils.isEmpty(emptyArray));
    }

    
    /*
	 * 测试Collection不为空
	 */
    @Test
    public static void testCollectionNotEmpty() {
        List<Integer> list = Arrays.asList(1, 2, 3);
        boolean listWithPositiveSize = EmptyUtils.notEmpty(list);//判断是否不为空
        assertTrue(listWithPositiveSize);//assertTrue/False([String message,]boolean condition);
       // 判断一个条件是true还是false。感觉这个最好用了，不用记下来那么多的方法名。

        List<Integer> emptyList = new ArrayList<Integer>();
        boolean listWithZeroSize = EmptyUtils.notEmpty(emptyList);
        assertFalse(listWithZeroSize);//判断这个条件是错的 

        List<Integer> nullList = null;
        boolean nullEmpty = EmptyUtils.notEmpty(nullList);
        assertFalse(nullEmpty);

        Set<Integer> set = new HashSet<Integer>();
        set.add(100);
        boolean setWithPositiveSize = EmptyUtils.notEmpty(set);
        assertTrue(setWithPositiveSize);

        Set<Integer> nullSet = null;
        assertFalse(EmptyUtils.notEmpty(nullSet));

        Set<Integer> emptySet = new HashSet<Integer>();
        assertFalse(EmptyUtils.notEmpty(emptySet));
    }

   /*
    *  判断Map不为空
    */
    @Test
    public static void testMapNotEmpty() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("mapTest", "mapTestValue");
        assertTrue(EmptyUtils.notEmpty(map));

        Map<String, Object> nullEmpty = null;
        assertFalse(EmptyUtils.notEmpty(nullEmpty));

        Map<String, Object> emptyMap = new HashMap<String, Object>();
        assertFalse(EmptyUtils.notEmpty(emptyMap));
    }

    /*
     * 判断数组不为空
     */
    @Test
    public static void testObjectArrayNotEmpty() {
        Integer[] array = { 1, 2, 3 };
        assertTrue(EmptyUtils.notEmpty(array));

        Integer[] nullArray = null;
        assertFalse(EmptyUtils.notEmpty(nullArray));

        Integer[] emptyArray = {};
        assertFalse(EmptyUtils.notEmpty(emptyArray));
    }
}
